package com.hulk.ratel.config;

import net.javacrumbs.shedlock.core.LockProvider;
import net.javacrumbs.shedlock.provider.jdbctemplate.JdbcTemplateLockProvider;
import net.javacrumbs.shedlock.spring.annotation.EnableSchedulerLock;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.scheduling.annotation.EnableScheduling;

import javax.annotation.Resource;
import javax.sql.DataSource;

/**
 * @Author: hulk
 * @E-mail: 29572320@qq.com
 * @Date: Create in 2019-05-18 22:37
 * @Version: 1.0.0
 * @Modify by:
 * Class description
 * @see https://www.cnblogs.com/gutousu/p/10235160.html
 * @see https://www.cnblogs.com/nickhan/p/10434604.html
 * @see https://github.com/lukas-krecan/ShedLock
 */
@Configuration
@EnableScheduling
@EnableSchedulerLock(defaultLockAtMostFor = "PT30S")
public class ShedLockConfig {

    @Resource
    private DataSource dataSource;

    @Bean
    public LockProvider lockProvider(){
        return new JdbcTemplateLockProvider(dataSource);
    }

}
